package recursion.leetcode.editor.cn;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class FileDeleteLinesWithRegex  {
    public static void main(String[] args) {
        String filename = "F:\\oneDrive\\桌面\\forward.852.sql";
        String regex = "INSERT INTO `fawkes`.`sys_api_log` .*|INSERT INTO `fawkes`.`sys_usual_log` .*|UPDATE `fawkesBpm`.*|DELETE FROM `fawkesBpm`.*|INSERT INTO `fawkesBpm`.*";
        String regex1 = "UPDATE `fawkes`.*|DELETE FROM `fawkes`.*|INSERT INTO `fawkes`.*";
        String regex2 = "DELETE FROM `fawkesBpm`.*";
        String regex3 = "INSERT INTO `fawkesBpm`.*";
// 1 摘要 2 简单介绍项目  3背景  4回应题目1  567 回应题目 2   8  9
        List<String> lines = new ArrayList<>();

        try (BufferedReader reader = new BufferedReader(new FileReader(filename))) {
            String line;
            // 读取所有行
            while ((line = reader.readLine()) != null) {
                // 使用正则表达式匹配行
                if (!line.matches(regex) &&line.matches(regex1)) {
                    lines.add(line);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        try (BufferedWriter writer = new BufferedWriter(new FileWriter(filename))) {
            // 将更新后的内容写回文件
            for (String line : lines) {
                writer.write(line);
                writer.newLine();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}